package com.zhiyou100.service;

import com.zhiyou100.entity.Teacher;
import com.zhiyou100.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 老师服务 实现类
 *
 * @author yang
 * @className TeacherServiceImpl
 * @packageName com.zhiyou100.service
 * @Description TODO 老师服务 实现类
 * @date 2020-08-25 19:19
 */

@Repository
public class TeacherServiceImpl implements TeacherService {

    private TeacherMapper mapper;

    @Override
    @Autowired
    public void setMapper(TeacherMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public List<Teacher> getAll() {
        return mapper.getAll();
    }

    @Override
    public Teacher getOneByTid(Integer tid) {
        return mapper.getOneByTid(tid);
    }

    @Override
    public boolean deleteOneByTid(Integer tid) {
        return mapper.delOneByTid(tid) != 0;
    }

    @Override
    public boolean updateOne(Teacher teacher) {
        return mapper.updateOne(teacher) != 0;
    }

    @Override
    public boolean addOne(Teacher teacher) {
        final Teacher oneByTid = mapper.getOneByTid(teacher.getTid());
        if (oneByTid != null) {
            return false;
        } else {
            return mapper.addOne(teacher) != 0;
        }
    }

    @Override
    public boolean login(Integer tid, String tpwd) {
        final Teacher teacher = mapper.signIn(tid, tpwd);
        return teacher != null;
    }


}
